package com.lxy.user.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.lxy.common.exception.BadRequestException;
import lombok.Getter;

@Getter
public enum Permission {
    REGULAR_USER(1, "普通用户"),
    REPAIR_USER(2, "维修人员"),
    DEVICE_ADMINISTRATOR(3,"设备管理人员"),
    SYSTEM_ADMINISTRATOR(4,"系统管理员")
    ;

    @EnumValue
    int value;
    String desc;

    Permission(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static Permission of(int value) {
        if (value == 1) {
            return REGULAR_USER;
        }
        if (value == 2) {
            return REPAIR_USER;
        }
        if (value == 3) {
            return DEVICE_ADMINISTRATOR;
        }
        if (value == 4) {
            return SYSTEM_ADMINISTRATOR;
        }
        throw new BadRequestException("账户状态错误");
    }
}